<template>
	<view class="my-nav">
		<view class="nav">
			<scroll-view scroll-x="true" class="catalogs">
				<view class="catalog" :class="{active:cataIndex==index}" v-for="(catalog,index) in catalogs"
					:key="catalog.id" @click="selectCatalog(index,catalog.id)" v-if="catalog.show_in_nav==1">
					{{catalog.cat_name}}
				</view>
				<view class="catalog">

				</view>
				<view class="catalog">

				</view>

			</scroll-view>
			<view class="catalog-edit" @click="openPopup">
				<u-icon name="list"></u-icon>
			</view>
		</view>
		<view>
			<u-popup 
				:show="popup.show" 
				:round="popup.round" 
				:overlay="popup.overlay" 
				:mode="popup.mode" 
				@close="close"
				:closeable="popup.closeable">
				<view class="u-popup-slot" :style="{height:popup.height+'vh'}">
					<view class="popup-catalogs">
						<view class="popup-in-catalog">
							<view class="left">
								<view class="my-catalogo">
									我的分类
								</view>
								<view class="in-catalog">点击进入分类</view>
							</view>

							<view class="edit" @click="minusShow">
								<u-icon name="edit-pen-fill"></u-icon>
							</view>

						</view>
						<view class="popup-catalogs-show">
							<view class="item" v-for="(catalog,index) in catalogs" v-if="catalog.show_in_nav==1"
								:key="catalog.id"
								>
								{{catalog.cat_name}}
								<u-icon class="minus" 
								:class="{minusshow:minusshow}"   
								color="#2979ff" 
								name="minus-circle"
								@click="minus(catalog.id)"
								></u-icon>
							</view>

						</view>

						<view class="popup-catalogs-hidden">
							<view class="item" v-for="(catalog,index) in catalogs" v-if="catalog.show_in_nav==0"
								:key="catalog.id">
								{{catalog.cat_name}}

								<u-icon class="add"
								 color="#ff9900" 
								 name="plus-circle-fill" 
								 @click="add(catalog.id)"
								 ></u-icon>


							</view>

						</view>

					</view>

				</view>
			</u-popup>
		</view>
	</view>

</template>

<script>
	import {mapMutations} from 'vuex';
	export default {
		name: "w-nav",
		props: {
			catalogs: {
				type: Array,
				required: true,
			},
			popup: {
				type: Object,
				default: function() {
					//默认值其效果,必须传值是undifined
					return {
						show: false,
						round: 10,
						overlay: true,
						mode: 'bottom',
						closeable: true,
						height: 90
					}
				}
			}

		},
		data() {
			return {
				cataIndex: 0,
				minusshow:false

			};
		},
		methods: {
			...mapMutations(['changeAddCatalogByid','changeMinusCatalogByid']),
			selectCatalog(index, id) {
				this.cataIndex = index;

				this.$emit('getCatalogId', id); //定义自定义事件 id参数
			},
			close() {
				this.popup.show = false
			},
			openPopup() {
				this.popup.show = true
			},
			add(id){
				this.changeAddCatalogByid(id);
				//console.log("pupop",id)
				this.$emit("getPupopCatalogId",id);
			},
			minusShow(){
				this.minusshow=!this.minusshow;
			},
			minus(id){
				console.log(id)
				this.changeMinusCatalogByid(id)
				
			}
			
		}
	}
</script>

<style scoped>
	.my-nav{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 99999;
		background-color: white;
		
	}
	
	.nav {
		position: relative;
	}

	.catalogs {
		white-space: nowrap;
		height: 50px;
		line-height: 50px;
		border-top: 1px solid #C8C9CC;
		border-bottom: 1px solid #C8C9CC;
		font-size: 12px;


	}

	.catalog {
		display: inline;

		margin: 0 10px;
	}

	.active {

		border-bottom: 2px solid #2979FF;
	}

	.catalog-edit {
		height: 49px;
		width: 40px;
		position: absolute;
		top: 1px;
		right: 0;
		background-color: white;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.popup-catalogs {

		margin: 50px 10px 0;


	}

	.popup-in-catalog {
		display: flex;
		justify-content: space-between;
		align-items: center;

		border-bottom: 1px solid #3C9CFF;
	}

	,
	.popup-in-catalog .left {
		display: flex;
		height: 30px;
		line-height: 30px;
		align-items: baseline;

	}

	.my-catalogo {
		font-size: 20px;
	}

	.in-catalog {
		font-size: 10px;
		color: #C6C7CB;
		margin-left: 10px;
		

	}

	.popup-catalogs-hidden {
		margin-top: 100px;
	}

	.popup-catalogs-show,
	.popup-catalogs-hidden {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;/* 换行 */
		margin: 10px 0;
	}

	.popup-catalogs-show>.item,
	.popup-catalogs-hidden>.item {
		padding: 5px;
		position: relative;
		border: 1px solid #BBBCC6;
		margin: 5px 5px;
		font-size: 8px;
	}

	.popup-catalogs-hidden .add {
		position: absolute;
		top: -8px;
		z-index: 99999;
		right: -8px;

	}

	.popup-catalogs-show .minus {
		position: absolute;
		top: -8px;
		z-index: 99999;
		right: -8px;
		display: none;

	}
	.minusshow{
		display: block !important;
	}
	.popup-catalogs-hidden{
		margin-top: 100px;
	}
</style>
